
package com.kugou.game.sdk.ui.activity;

import com.kugou.game.sdk.api.common.ActivityOrientation;
import com.kugou.game.sdk.api.common.User;
import com.kugou.game.sdk.base.BaseCommonTitleFragmentActivity;
import com.kugou.game.sdk.core.FolderManager;
import com.kugou.game.sdk.core.PayManager;
import com.kugou.game.sdk.core.SDKActions;
import com.kugou.game.sdk.core.SDKControler;
import com.kugou.game.sdk.core.UserManager;
import com.kugou.game.sdk.core.VipManager;
import com.kugou.game.sdk.statistics.StatCmd;
import com.kugou.game.sdk.statistics.StaticsManager;
import com.kugou.game.sdk.ui.dialog.BaseConfirmDialog;
import com.kugou.game.sdk.ui.dialog.ModifyUserPhotoDialog;
import com.kugou.game.sdk.ui.fragment.AccountSecurityFragment;
import com.kugou.game.sdk.ui.fragment.MyCouponFragment;
import com.kugou.game.sdk.ui.fragment.SetLoginPsdFragment;
import com.kugou.game.sdk.ui.widget.FloatView;
import com.kugou.game.sdk.ui.widget.GameFitGridRelativeLayout;
import com.kugou.game.sdk.ui.widget.RoundImageView;
import com.kugou.game.sdk.utils.AppUtil;
import com.kugou.game.sdk.utils.AsyncImageLoader;
import com.kugou.game.sdk.utils.AsyncImageLoader.ImageCallback;
import com.kugou.game.sdk.utils.Rx;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.ArrayList;

/**
 * 描述:用户中心页面
 * 
 * @author liux
 * @since 2013-12-17 上午10:49:31
 */
public class UserCenterActivity extends BaseCommonTitleFragmentActivity implements OnClickListener,
        ImageCallback {

    /** 正式与非正式用户中心布局 */
    private LinearLayout layoutFormalAccount;

    private LinearLayout layoutInformalAccount;

    /** 用户昵称头像 */
    private LinearLayout layoutUserInfo;

    // private LinearLayout layoutUserCenterTop;

    /** 我的消息 */
    private RelativeLayout layoutMyMessages;

    /** 激活临时账号模块 */
    private RelativeLayout layoutTemporaryAccount;

    /** 横竖屏通用切换账号模块 */
    private RelativeLayout layoutCommonChangeAccount;

    /** 横版切换账号模块 */
    private RelativeLayout layoutLandChangeAccount;

    /** 账号安全模块 */
    private RelativeLayout layoutAccountSecurity;

    /** 我的代金券模块 */
    private RelativeLayout layoutMyCoupon;

    /** 用户中心Banner */
    private GameFitGridRelativeLayout layoutUserCenterBanner;

    private RelativeLayout layoutUserCenterBannerLand;
    
    private ImageView ivUserCenterBanner;

    private AsyncImageLoader mAsyncImageLoader;

    private TextView tvUserAccount;// 账号

    private TextView tvNickName;// 昵称

    private TextView tvKubiNum;// 钱包余额

    private Button btnKubiRecharge, btnBackGame;

    private RoundImageView ivUserCenterPhoto;// 用户头像

    private ImageView ivUserCenterVipPhoto;// Vip头像角标

    private TextView tvMessagesCount;// 消息数量文本

    private TextView tvKubiRechargePreferential;// 游币充值优惠信息文本

    private ModifyUserPhotoDialog modifyUserPhotoDialog;

    private BaseConfirmDialog activationAccountDialog, changeAccountDialog;

    private ImageView mImage1, mImage2, mImage3, mImage4;// 账号安全图标

    private TextView tvSecurityMark;// 账号安全评分

    private RelativeLayout rlSecurityScore, rlScoreAchieved;// 评分布局

    private int defaultBannerImageId;

    /**
     * 当前用户信息
     */
    private User currentUser;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        currentUser = UserManager.getInstance().getCurrentUserInternal();
        int layoutId = Rx.layout.kg_acitvity_user_center;
        defaultBannerImageId = Rx.drawable.kg_banner_default;
        if (SDKControler.getActivityOrientation() == ActivityOrientation.LANDSCAPE) {
            layoutId = Rx.layout.kg_acitvity_user_center_land;
            defaultBannerImageId = Rx.drawable.kg_banner_default_land;
        }
        if (layoutId != 0) {
            setContentView(layoutId);
            // 设置标题
            setCommonTitle(Rx.string.kg_kugou_game_center);
            setCommonRightImageViewVisibility(View.GONE);

            // 设置View界面
            mAsyncImageLoader = new AsyncImageLoader();
            initViews();
            // 显示vip图标
            showVipIcon();

            updateViewWithUserState();
        } else {
            showToast(Rx.string.kg_layout_not_found);
        }

        if (currentUser == null || !currentUser.isRegistered()) {
            showActivationAccountDialog();
        }
    }

    private void updateViewWithUserState() {
        if (currentUser != null && currentUser.isRegistered()) {
            layoutUserInfo.setVisibility(View.VISIBLE);
            layoutFormalAccount.setVisibility(View.VISIBLE);
            layoutInformalAccount.setVisibility(View.GONE);
            if (SDKControler.getActivityOrientation() == ActivityOrientation.PORTRAIT) {
                setCommonTitle(null);
                mTitleBar.setBackgroundResource(Rx.drawable.kg_img_userinfo_bg_por_top);
            }
        } else {
            layoutUserInfo.setVisibility(View.GONE);
            layoutFormalAccount.setVisibility(View.GONE);
            layoutInformalAccount.setVisibility(View.VISIBLE);
        }

        // 如果是登录的正式用户，请求个人信息
        if (currentUser != null && currentUser.isRegistered()) {
            // 设置账号
            tvUserAccount.setText(TextUtils.isEmpty(currentUser.getAccountName()) ? ""
                    : currentUser.getAccountName());
            // 设置昵称
            tvNickName.setText(TextUtils.isEmpty(currentUser.getNickName()) ? "" : currentUser
                    .getNickName());
            // 设置钱包余额
            tvKubiNum.setText(currentUser.getKubiNum() + "");
            // 设置未读消息数量
            setUnreadmailsNum();
            // 设置头像
            setUserHead();
            showVipHeadIcon();
            // 设置安全评分图标
            refreshSecurityScore();
            // 设置banner
            setBanner();
            if (PayManager.hasYoubiRechargepreferential()) {
                tvKubiRechargePreferential.setText("("
                        + PayManager.getKubiRechargePreferentialTitle() + ")");
            } else {
                tvKubiRechargePreferential.setText(" ");
            }
        }
    }

    @Override
    public void setupActions(ArrayList<String> actions) {
        super.setupActions(actions);
        actions.add(SDKActions.ACTION_YOUBI_RATIO_CHANGE);
        actions.add(SDKActions.ACTION_READ_ONE_EMAIL);
        actions.add((SDKActions.ACTION_DELETE_ONE_UNREAD_EMAIL));
        actions.add(SDKActions.ACTION_UPDATE_BIND_PHONE_SUCCESS);
        actions.add(SDKActions.ACTION_MODIFY_HEAD_SUCCESS);
        actions.add(SDKActions.ACTION_SET_LOGIN_PSD_SUCCESS);
        actions.add(SDKActions.ACTION_KUBI_NUM_CHANGE);
        actions.add(SDKActions.ACTION_CHANGE_TO_VIP);
        actions.add(SDKActions.ACTION_AUTO_REGISTER_SUCCESS);
        actions.add(SDKActions.ACTION_UPDATE_NICKNAME_SUCCESS);
    }

    private int messageId;

    @Override
    public void handleBroadcast(Context context, Intent intent) {
        super.handleBroadcast(context, intent);
        String action = intent.getAction();
        // 当游币充值优惠信息发生变化时，刷新入口信息
        if (SDKActions.ACTION_YOUBI_RATIO_CHANGE.equals(action)
                && tvKubiRechargePreferential != null) {
            if (PayManager.hasYoubiRechargepreferential()) {
                tvKubiRechargePreferential.setText("("
                        + PayManager.getKubiRechargePreferentialTitle() + ")");
            } else {
                tvKubiRechargePreferential.setText(" ");
            }
        } else if (action != null
                && (SDKActions.ACTION_READ_ONE_EMAIL.equals(action) || SDKActions.ACTION_DELETE_ONE_UNREAD_EMAIL
                        .equals(action))) {
            CharSequence charSequence = tvMessagesCount.getText();
            int msgId = intent.getIntExtra(MSG_ID, -1);
            if (!TextUtils.isEmpty(charSequence) && msgId > 0) {
                // 防止同一条信息重复处理
                if (messageId == msgId) {
                    return;
                } else {
                    messageId = msgId;
                }
                int num = Integer.valueOf(charSequence.toString());
                int leftUnreadNum = num - 1;
                UserManager.getInstance().getCurrentUserInternal().setUnreadmails(leftUnreadNum);
                if (leftUnreadNum <= 0) {
                    tvMessagesCount.setVisibility(View.GONE);
                } else {
                    tvMessagesCount.setText(String.valueOf(leftUnreadNum));
                }
            }
        } else if (SDKActions.ACTION_UPDATE_BIND_PHONE_SUCCESS.equals(action)) {
            User user = UserManager.getInstance().getCurrentUserInternal();
            if (user != null && !TextUtils.isEmpty(user.getAccountName())) {
                tvUserAccount.setText(user.getAccountName());
            }
        } else if (SDKActions.ACTION_MODIFY_HEAD_SUCCESS.equals(action)) {
            if (mAsyncImageLoader != null) {
                mAsyncImageLoader.clearBitmap();
            }
            setUserHead();
        } else if (SDKActions.ACTION_KUBI_NUM_CHANGE.equals(action)) {
            tvKubiNum.setText(currentUser.getKubiNum() + "");
        } else if (SDKActions.ACTION_SET_LOGIN_PSD_SUCCESS.equals(action)) {
            setUnreadmailsNum();
        } else if (SDKActions.ACTION_CHANGE_TO_VIP.equals(action)) {
            showVipHeadIcon();
        } else if (SDKActions.ACTION_AUTO_REGISTER_SUCCESS.equals(action)) {
            updateViewWithUserState();
        } else if (SDKActions.ACTION_UPDATE_NICKNAME_SUCCESS.equals(action)) {
            // 设置昵称
            tvNickName.setText(TextUtils.isEmpty(currentUser.getNickName()) ? "" : currentUser
                    .getNickName());
        }
    }

    /**
     * 游客模式进入用户中心时弹窗
     */
    private void showActivationAccountDialog() {
        activationAccountDialog = new BaseConfirmDialog(UserCenterActivity.this);
        activationAccountDialog.setDialogTitle("温馨提示");
        activationAccountDialog.setMessage("尊敬的主人：\n您目前处于试玩模式，想要永久保存您的游戏记录，只要完成注册激活即可");
        activationAccountDialog.setCancelText("知道了");
        activationAccountDialog.setOKBtnText("激活账号");
        activationAccountDialog.setCancelClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                activationAccountDialog.dismiss();
            }
        });
        activationAccountDialog.setOKClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                activationAccountDialog.dismiss();
                Intent intent = new Intent(UserCenterActivity.this, RegisterByPhoneActivity.class);
                intent.putExtra(FROM_ACTION_KEY, FROM_NORMAL);
                startActivity(intent);
            }
        });
        activationAccountDialog.show();
    }

    /**
     * 游客模式切换账号弹框
     */
    private void showChangeAccountDialog() {
        changeAccountDialog = new BaseConfirmDialog(UserCenterActivity.this);
        changeAccountDialog.setCloseVisibility(View.VISIBLE);
        changeAccountDialog.setDialogTitle("温馨提示");
        changeAccountDialog.setMessage("尊敬的主人：\n您目前处于试玩模式，若切换账号，会丢失当前的游戏记录，建议注册并激活游戏账号，保存游戏记录！");
        changeAccountDialog.setCancelText("切换账号");
        changeAccountDialog.setOKBtnText("激活账号");
        changeAccountDialog.setCancelClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(UserCenterActivity.this, LoginActivity.class);
                intent.putExtra(FROM_ACTION_KEY, FROM_CHANGE_ACCOUNT);
                startActivity(intent);
                finish();
            }
        });
        changeAccountDialog.setOKClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                changeAccountDialog.dismiss();
                Intent intent = new Intent(UserCenterActivity.this, RegisterByPhoneActivity.class);
                intent.putExtra(FROM_ACTION_KEY, FROM_NORMAL);
                startActivity(intent);
            }
        });
        changeAccountDialog.show();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (modifyUserPhotoDialog != null && modifyUserPhotoDialog.isShowing()) {
            modifyUserPhotoDialog.dismiss();
        }
        if (changeAccountDialog != null && changeAccountDialog.isShowing()) {
            changeAccountDialog.dismiss();
        }
        if (activationAccountDialog != null && activationAccountDialog.isShowing()) {
            activationAccountDialog.dismiss();
        }
    }

    /**
     * 初始化界面控件
     */
    @SuppressLint("NewApi")
    private void initViews() {
        // 用户中心布局
        layoutFormalAccount = (LinearLayout) findViewById(Rx.id.kg_formal_account_layout);
        layoutInformalAccount = (LinearLayout) findViewById(Rx.id.kg_informal_account_layout);
        // 我的代金券
        layoutMyCoupon = (RelativeLayout) findViewById(Rx.id.kg_layout_my_coupon);
        layoutMyCoupon.setOnClickListener(this);

        // 用户中心Banner相关
        if (SDKControler.getActivityOrientation() == ActivityOrientation.PORTRAIT){ 
            layoutUserCenterBanner = (GameFitGridRelativeLayout) findViewById(Rx.id.kg_rl_usercenter_banner);
            layoutUserCenterBanner.setmScale(3.6f);
            ivUserCenterBanner = (ImageView) findViewById(Rx.id.kg_iv_usercenter_banner);
            layoutUserCenterBanner.setOnClickListener(this);
        }else {
            layoutUserCenterBanner = (GameFitGridRelativeLayout) findViewById(Rx.id.kg_rl_usercenter_banner);
            layoutUserCenterBanner.setVisibility(View.GONE);
            layoutUserCenterBannerLand = (RelativeLayout) findViewById(Rx.id.kg_rl_usercenter_banner_land);
            ivUserCenterBanner = (ImageView) findViewById(Rx.id.kg_iv_usercenter_banner_land);
            layoutUserCenterBannerLand.setOnClickListener(this);
        }
        
        
        
        // 用户昵称头像模块
        // layoutUserCenterTop = (LinearLayout)
        // findViewById(Rx.id.kg_usercenter_top_layout);
        layoutUserInfo = (LinearLayout) findViewById(Rx.id.kg_layout_user_info);
        layoutUserInfo.setOnClickListener(this);
        tvUserAccount = (TextView) findViewById(Rx.id.kg_tv_username);
        tvNickName = (TextView) findViewById(Rx.id.kg_tv_nickname);
        tvKubiNum = (TextView) findViewById(Rx.id.kg_tv_kubi_num);
        btnKubiRecharge = (Button) findViewById(Rx.id.kg_btn_kubi_recharge);
        tvMessagesCount = (TextView) findViewById(Rx.id.kg_tv_my_messages_count);
        tvMessagesCount.setVisibility(View.GONE);
        tvKubiRechargePreferential = (TextView) findViewById(Rx.id.kg_tv_kubi_recharge_preferential);
        layoutMyMessages = (RelativeLayout) findViewById(Rx.id.kg_layout_my_messages);
        ivUserCenterPhoto = (RoundImageView) findViewById(Rx.id.kg_iv_user_photo);
        ivUserCenterVipPhoto = (ImageView) findViewById(Rx.id.kg_iv_vip_head);
        ivUserCenterPhoto.setOnClickListener(this);
        btnKubiRecharge.setOnClickListener(this);

        // 激活临时账号
        layoutTemporaryAccount = (RelativeLayout) findViewById(Rx.id.kg_layout_temporary_account);
        layoutTemporaryAccount.setOnClickListener(this);
        // 切换账号
        layoutCommonChangeAccount = (RelativeLayout) findViewById(Rx.id.kg_layout_common_change_account);
        layoutCommonChangeAccount.setOnClickListener(this);
        layoutLandChangeAccount = (RelativeLayout) findViewById(Rx.id.kg_layout_land_change_account);
        if (layoutLandChangeAccount != null) {
            layoutLandChangeAccount.setOnClickListener(this);
        }
        layoutAccountSecurity = (RelativeLayout) findViewById(Rx.id.kg_layout_account_security);
        layoutAccountSecurity.setOnClickListener(this);

        // 我的消息
        layoutMyMessages.setOnClickListener(this);

        // 安全评分相关
        rlSecurityScore = (RelativeLayout) findViewById(Rx.id.kg_rl_security_score);
        rlScoreAchieved = (RelativeLayout) findViewById(Rx.id.kg_rl_security_score_achieved);
        tvSecurityMark = (TextView) findViewById(Rx.id.kg_security_mark);
        mImage1 = (ImageView) findViewById(Rx.id.kg_security_img_1);
        mImage2 = (ImageView) findViewById(Rx.id.kg_security_img_2);
        mImage3 = (ImageView) findViewById(Rx.id.kg_security_img_3);
        mImage4 = (ImageView) findViewById(Rx.id.kg_security_img_4);

        // 底部返回游戏按钮
        btnBackGame = (Button) findViewById(Rx.id.kg_btn_back_game);
        btnBackGame.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v == layoutTemporaryAccount) {
            Intent intent = new Intent(UserCenterActivity.this, RegisterByPhoneActivity.class);
            startActivity(intent);
        } else if (v == layoutMyMessages) {

            // 如果有未读邮件，则点击后通知悬浮窗隐藏红点显示
            User user = UserManager.getInstance().getCurrentUserInternal();
            if (user != null && user.getUnreadmails() > 0) {
                user.setUnreadMailReminded(true);
                FloatView.createAndSendUpdateIntent(UserCenterActivity.this,
                        SDKActions.ACTION_UNREAD_EMAIL_CLICKED);
            }

            if (user.isSetKugouPsd()) {
                // 跳转到消息列表页面
                Intent intent = new Intent(UserCenterActivity.this, MessageListActivity.class);
                startActivity(intent);
            } else {
                startActivity(CommonSdkActivity.creatIntent(this,
                        SetLoginPsdFragment.class.getName(), Rx.string.kg_set_login_psd));
            }

        } else if (v == layoutAccountSecurity) {
            User user = UserManager.getInstance().getCurrentUserInternal();
            if (user.isSetKugouPsd()) {
                startActivity(CommonSdkActivity.creatIntent(this,
                        AccountSecurityFragment.class.getName(), Rx.string.kg_accout_security));
            } else {
                startActivity(CommonSdkActivity.creatIntent(this,
                        SetLoginPsdFragment.class.getName(), Rx.string.kg_set_login_psd));
            }
        } else if (v == layoutUserInfo || v == ivUserCenterPhoto) {
            User user = UserManager.getInstance().getCurrentUserInternal();
            if (user.isSetKugouPsd()) {
                Intent intent = new Intent(UserCenterActivity.this, UserInfoActivity.class);
                startActivity(intent);

                // 发送统计--点击进入个人信息页面
                StaticsManager.sendCommonStatis(StatCmd.CMD_USERCENTER_CLICK_USER_INFO);
            } else {
                startActivity(CommonSdkActivity.creatIntent(this,
                        SetLoginPsdFragment.class.getName(), Rx.string.kg_set_login_psd));
            }
        } else if (v == layoutCommonChangeAccount) {
            changeAccount();
        } else if (v == layoutLandChangeAccount) {
            changeAccount();
        } else if (v == layoutMyCoupon) {
            startActivity(CommonSdkActivity.creatIntent(this, MyCouponFragment.class.getName(),
                    Rx.string.kg_my_coupon_page_title));
            // 发送统计--点击我的代金券
            StaticsManager.sendCommonStatis(StatCmd.CMD_USERCENTER_CLICK_COUPON);
        } else if (v == layoutUserCenterBanner) {
            if (currentUser.getBannerInfo() == null) {
                RechargeActivity.showYoubiRechargePage(UserCenterActivity.this, 2);
                return;
            }
                if (currentUser.getBannerInfo().getType() == 1) {
                    // 跳转的H5页面Url
                    String url = currentUser.getBannerInfo().getUrl();
                    mContext.startActivity(new Intent(mContext, TopicActivity.class).putExtra("Url",
                            url));
                } else if (currentUser.getBannerInfo().getType() == 2
                        || currentUser.getBannerInfo().getType() == 0) {
                    RechargeActivity.showYoubiRechargePage(UserCenterActivity.this, 2);
                }
            // 发送统计--点击banner
            StaticsManager.sendCommonStatis(StatCmd.CMD_USERCENTER_CLICK_BANNER);
        } else if (v == layoutUserCenterBannerLand) {
            if (currentUser.getBannerInfo() == null) {
                RechargeActivity.showYoubiRechargePage(UserCenterActivity.this, 2);
                return;
            }
                if (currentUser.getBannerInfo().getType() == 1) {
                    // 跳转的H5页面Url
                    String url = currentUser.getBannerInfo().getUrl();
                    mContext.startActivity(new Intent(mContext, TopicActivity.class).putExtra("Url",
                            url));
                } else if (currentUser.getBannerInfo().getType() == 2
                        || currentUser.getBannerInfo().getType() == 0) {
                    RechargeActivity.showYoubiRechargePage(UserCenterActivity.this, 2);
                }
            // 发送统计--点击banner
            StaticsManager.sendCommonStatis(StatCmd.CMD_USERCENTER_CLICK_BANNER);
        }else if (v == btnKubiRecharge) {
            RechargeActivity.showYoubiRechargePage(UserCenterActivity.this, 1);
            // 发送统计--点击充值
            StaticsManager.sendCommonStatis(StatCmd.CMD_USERCENTER_CLICK_RECHARGE);
        } else if (v == btnBackGame) {
            // 回到游戏
            Intent intent = new Intent(SDKActions.ACTION_BACK_TO_GAME);
            this.sendBroadcast(intent);
        }
    }

    /**
     * 切换账号
     */
    private void changeAccount() {
        User user = UserManager.getInstance().getCurrentUserInternal();
        Intent intent = null;
        if (user != null && user.isRegistered()) {
            intent = new Intent(UserCenterActivity.this, LoginActivity.class);
            intent.putExtra(FROM_ACTION_KEY, FROM_CHANGE_ACCOUNT);
            startActivity(intent);
        } else {
            showChangeAccountDialog();
        }
    }

    /**
     * 设置头像
     */
    private void setUserHead() {
        String imageUrl = currentUser.getHeadIconUrl();
        String savePath = FolderManager.IMAGE_CACHE_FOLDER + AppUtil.getFileNameFromUrl(imageUrl);
        loadImage(imageUrl, savePath);
    }

    /**
     * 显示vip角标
     */
    private void showVipHeadIcon() {
        if (VipManager.getInstance().isVip()) {
            ivUserCenterVipPhoto.setVisibility(View.VISIBLE);
        }
    }

    /**
     * 设置未读消息数量红点
     */
    private void setUnreadmailsNum() {
        int unreadMailsNum = UserManager.getInstance().getCurrentUserInternal().getUnreadmails();
        if (unreadMailsNum > 0) {
            tvMessagesCount.setText(unreadMailsNum + "");
            tvMessagesCount.setVisibility(View.VISIBLE);
        } else {
            tvMessagesCount.setVisibility(View.GONE);
        }
    }

    /**
     * 加载图片
     * 
     * @param imageUrl
     * @param savePath
     */
    private void loadImage(String imageUrl, String savePath) {
        if (mAsyncImageLoader == null)
            return;
        mAsyncImageLoader.loadImage(this, imageUrl, imageUrl, savePath, this);
    }

    @Override
    public void imageLoaded(Bitmap bitmap, String key) {
        if (bitmap != null) {
            ivUserCenterPhoto.setImageBitmap(bitmap);
        }
    }

    private void refreshSecurityScore() {

        if (currentUser.getSecurityScore() == 100) {
            rlSecurityScore.setVisibility(View.GONE);
            rlScoreAchieved.setVisibility(View.VISIBLE);
        } else {
            rlScoreAchieved.setVisibility(View.GONE);
            rlSecurityScore.setVisibility(View.VISIBLE);
            // 安全图标
            if (!TextUtils.isEmpty(currentUser.getBindPhoneNum())) {
                mImage1.setImageResource(Rx.drawable.kg_security_phone_binded);
            } else {
                mImage1.setImageResource(Rx.drawable.kg_security_phone_default);
            }
            if (!TextUtils.isEmpty(currentUser.getSecurityEmail())) {
                mImage2.setImageResource(Rx.drawable.kg_security_email_binded);
            } else {
                mImage2.setImageResource(Rx.drawable.kg_security_email_default);
            }
            if (currentUser.getSecurityQuestionId() != 255) {
                mImage3.setImageResource(Rx.drawable.kg_security_question_set);
            } else {
                mImage3.setImageResource(Rx.drawable.kg_security_question_default);
            }
            if (currentUser.isSetIdentity()) {
                mImage4.setImageResource(Rx.drawable.kg_security_identity_binded);
            } else {
                mImage4.setImageResource(Rx.drawable.kg_security_identity_default);
            }
            // 安全评分
            tvSecurityMark.setText("账号安全:" + String.valueOf(currentUser.getSecurityScore()));
        }

    }

    private void setBanner() {
        if (currentUser.getBannerInfo() == null) {
            ivUserCenterBanner.setImageResource(defaultBannerImageId);
            return;
        }
        String bannerUrl = currentUser.getBannerInfo().getImageUrl();
        if (!TextUtils.isEmpty(bannerUrl) && bannerUrl != null) {
            String savePath = FolderManager.IMAGE_CACHE_FOLDER
                    + AppUtil.getFileNameFromUrl(bannerUrl);
            String key = bannerUrl;
            Bitmap bitmap = new AsyncImageLoader().loadImage(mContext, key, bannerUrl, savePath,
                    new ImageCallback() {

                        @Override
                        public void imageLoaded(Bitmap bitmap, String key) {
                            if (bitmap != null) {
                                ivUserCenterBanner.setImageBitmap(bitmap);
                            }
                        }
                    });
            if (bitmap != null) {
                ivUserCenterBanner.setImageBitmap(bitmap);
            }
        } else {
            ivUserCenterBanner.setImageResource(defaultBannerImageId);
        }
        // ToastUtil.showMsg("" + bannerUrl);
    }

}
